#!/usr/bin/env python3

from progress.bar import Bar
from pwn import *
from randcrack import RandCrack

REQUIRED_INTEGER_COUNT = 624

rc = RandCrack()
io = remote('challenge.nahamcon.com', 30260)

with Bar('Progress', max=REQUIRED_INTEGER_COUNT) as progress_bar:
    for i in range(REQUIRED_INTEGER_COUNT):
        io.sendlineafter('> ', '2') # Roll the dice
        io.recvline()
        number = int(io.recvline())
        rc.submit(number)
        progress_bar.next()

io.sendlineafter('> ', '3') # Start a prediction
prediction = rc.predict_getrandbits(32)
io.sendlineafter('> ', str(prediction))
io.interactive()
